package cn.cihon.ubi.qorosauto.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/*
 * 次工具类定义一个Jedis连接池
 */
public class JedisUtil {

private static String REDIS_IP ="123.57.54.113";           
private static String REDIS_PORT ="6379";
private static JedisPool pool = null;
    
    /**
     * 构建redis连接池
     * 
     * @param ip
     * @param port
     * @return JedisPool
     */
    public static JedisPool getPool() {             //获取连接池
        if (pool == null) {
           
        	JedisPoolConfig config = new JedisPoolConfig();
    		config.setMaxTotal(1000);
    		config.setMaxIdle(50);
    		config.setMaxWaitMillis(10 * 1000);
            config.setTestOnBorrow(true);
            pool = new JedisPool(config, REDIS_IP, Integer.parseInt(REDIS_PORT));
        }
        return pool;
    }
    
    /**
     * 返还到连接池
     * 
     * @param pool 
     * @param redis
     */
    public static void returnResource(JedisPool pool, Jedis redis) {
        if (redis != null) {
        pool.returnResource(redis);
        }
    }
}
